import pool_util from "./pool_util";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

var DropsG = cc.Class({
    name:'dropsG',
    properties: {
        name:'',
        initPollCount:0,
        prefab:cc.Prefab
    }
});



@ccclass
export default class DropsGroup extends cc.Component {

    @property({type:DropsG})
    dropsG=[];

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        pool_util.batchInitObjPool(this,this.dropsG);
    }

    start () {

    }


    startAction(){
 
        this.schedule(this.createDrops,1);
    }
    createDrops(){
        switch(Math.round(Math.random()*20)){
            case 1:case 2:case 3:case 4:
            case 5: case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:
            case 17:
            this.getNewDrops(this.dropsG[0]);
            break;
            case 18:
            case 19:
            case 20:

            break;
        }
    }

    getNewDrops(info) {
        var poolName = info.name + 'Pool';
        var newNode = pool_util.genNewNode(this[poolName],info.prefab,this.node);
        var newV2 = this.getNewDropsPositon(newNode);
        newNode.setPosition(newV2);
        // newNode.getComponent(info.name).init();
    }

    getNewDropsPositon(newNode) {
        //位于上方，先不可见
        var randx = (Math.random()*2 -1)*(this.node.parent.width/2-newNode.width/2);
        var randy = this.node.parent.height/2+newNode.height/2;
        return cc.v2(randx,randy);
    }

    died(node){
        pool_util.backObjPool(this,node);
    }

    // update (dt) {}
}
